from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-27 14:02:08.602959
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 27, Feb, 2022
Time: 14:02:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2985
Nobs: 580.000 HQIC: -48.7116
Log likelihood: 6886.04 FPE: 5.37297e-22
AIC: -48.9755 Det(Omega_mle): 4.60679e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350094 0.068060 5.144 0.000
L1.Burgenland 0.107988 0.041334 2.613 0.009
L1.Kärnten -0.110653 0.021569 -5.130 0.000
L1.Niederösterreich 0.190576 0.086340 2.207 0.027
L1.Oberösterreich 0.124759 0.085283 1.463 0.144
L1.Salzburg 0.256586 0.043791 5.859 0.000
L1.Steiermark 0.036830 0.057836 0.637 0.524
L1.Tirol 0.101382 0.046670 2.172 0.030
L1.Vorarlberg -0.068368 0.041158 -1.661 0.097
L1.Wien 0.017913 0.075792 0.236 0.813
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051841 0.146594 0.354 0.724
L1.Burgenland -0.038150 0.089029 -0.429 0.668
L1.Kärnten 0.041468 0.046457 0.893 0.372
L1.Niederösterreich -0.204945 0.185966 -1.102 0.270
L1.Oberösterreich 0.460716 0.183691 2.508 0.012
L1.Salzburg 0.281870 0.094321 2.988 0.003
L1.Steiermark 0.114437 0.124572 0.919 0.358
L1.Tirol 0.304348 0.100523 3.028 0.002
L1.Vorarlberg 0.025519 0.088649 0.288 0.773
L1.Wien -0.027772 0.163247 -0.170 0.865
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199526 0.034708 5.749 0.000
L1.Burgenland 0.088519 0.021079 4.199 0.000
L1.Kärnten -0.007348 0.010999 -0.668 0.504
L1.Niederösterreich 0.239178 0.044030 5.432 0.000
L1.Oberösterreich 0.161718 0.043491 3.718 0.000
L1.Salzburg 0.039715 0.022332 1.778 0.075
L1.Steiermark 0.026660 0.029494 0.904 0.366
L1.Tirol 0.081874 0.023800 3.440 0.001
L1.Vorarlberg 0.053928 0.020989 2.569 0.010
L1.Wien 0.118294 0.038651 3.061 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119316 0.034688 3.440 0.001
L1.Burgenland 0.042429 0.021067 2.014 0.044
L1.Kärnten -0.013086 0.010993 -1.190 0.234
L1.Niederösterreich 0.169578 0.044005 3.854 0.000
L1.Oberösterreich 0.337356 0.043467 7.761 0.000
L1.Salzburg 0.099823 0.022319 4.473 0.000
L1.Steiermark 0.111166 0.029477 3.771 0.000
L1.Tirol 0.090078 0.023787 3.787 0.000
L1.Vorarlberg 0.061213 0.020977 2.918 0.004
L1.Wien -0.018247 0.038629 -0.472 0.637
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124441 0.065338 1.905 0.057
L1.Burgenland -0.045059 0.039681 -1.136 0.256
L1.Kärnten -0.045362 0.020706 -2.191 0.028
L1.Niederösterreich 0.136013 0.082886 1.641 0.101
L1.Oberösterreich 0.162240 0.081872 1.982 0.048
L1.Salzburg 0.285110 0.042039 6.782 0.000
L1.Steiermark 0.057773 0.055523 1.041 0.298
L1.Tirol 0.157117 0.044804 3.507 0.000
L1.Vorarlberg 0.097253 0.039512 2.461 0.014
L1.Wien 0.073559 0.072760 1.011 0.312
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079371 0.050903 1.559 0.119
L1.Burgenland 0.024689 0.030914 0.799 0.425
L1.Kärnten 0.053522 0.016132 3.318 0.001
L1.Niederösterreich 0.188231 0.064575 2.915 0.004
L1.Oberösterreich 0.331907 0.063785 5.204 0.000
L1.Salzburg 0.033508 0.032752 1.023 0.306
L1.Steiermark 0.006328 0.043256 0.146 0.884
L1.Tirol 0.119577 0.034906 3.426 0.001
L1.Vorarlberg 0.066209 0.030783 2.151 0.031
L1.Wien 0.098327 0.056686 1.735 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170720 0.061517 2.775 0.006
L1.Burgenland 0.005221 0.037360 0.140 0.889
L1.Kärnten -0.065973 0.019495 -3.384 0.001
L1.Niederösterreich -0.107443 0.078039 -1.377 0.169
L1.Oberösterreich 0.208955 0.077084 2.711 0.007
L1.Salzburg 0.053833 0.039581 1.360 0.174
L1.Steiermark 0.248222 0.052276 4.748 0.000
L1.Tirol 0.499479 0.042184 11.841 0.000
L1.Vorarlberg 0.064253 0.037201 1.727 0.084
L1.Wien -0.074003 0.068505 -1.080 0.280
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161399 0.068235 2.365 0.018
L1.Burgenland -0.002366 0.041440 -0.057 0.954
L1.Kärnten 0.062908 0.021624 2.909 0.004
L1.Niederösterreich 0.166037 0.086561 1.918 0.055
L1.Oberösterreich -0.055118 0.085502 -0.645 0.519
L1.Salzburg 0.208094 0.043903 4.740 0.000
L1.Steiermark 0.138775 0.057984 2.393 0.017
L1.Tirol 0.055753 0.046790 1.192 0.233
L1.Vorarlberg 0.146893 0.041263 3.560 0.000
L1.Wien 0.120757 0.075986 1.589 0.112
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.391951 0.040043 9.788 0.000
L1.Burgenland -0.004701 0.024319 -0.193 0.847
L1.Kärnten -0.021311 0.012690 -1.679 0.093
L1.Niederösterreich 0.199800 0.050798 3.933 0.000
L1.Oberösterreich 0.231606 0.050176 4.616 0.000
L1.Salzburg 0.036462 0.025764 1.415 0.157
L1.Steiermark -0.016333 0.034028 -0.480 0.631
L1.Tirol 0.090424 0.027458 3.293 0.001
L1.Vorarlberg 0.050783 0.024215 2.097 0.036
L1.Wien 0.044142 0.044592 0.990 0.322
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036418 0.101773 0.168307 0.138049 0.094266 0.080890 0.032599 0.208347
Kärnten 0.036418 1.000000 -0.027858 0.132088 0.048401 0.085332 0.443752 -0.067153 0.089116
Niederösterreich 0.101773 -0.027858 1.000000 0.309662 0.118306 0.269715 0.065398 0.151287 0.287587
Oberösterreich 0.168307 0.132088 0.309662 1.000000 0.212760 0.293748 0.166178 0.135266 0.235014
Salzburg 0.138049 0.048401 0.118306 0.212760 1.000000 0.122466 0.091137 0.104617 0.122450
Steiermark 0.094266 0.085332 0.269715 0.293748 0.122466 1.000000 0.134018 0.105764 0.032862
Tirol 0.080890 0.443752 0.065398 0.166178 0.091137 0.134018 1.000000 0.062840 0.150932
Vorarlberg 0.032599 -0.067153 0.151287 0.135266 0.104617 0.105764 0.062840 1.000000 -0.005466
Wien 0.208347 0.089116 0.287587 0.235014 0.122450 0.032862 0.150932 -0.005466 1.000000